#include "string_test.h"

#include <vector>
#include <fstream>
#include "string_util.h"

USING_NS_TEST;
USING_NS_STD;

elloop_test::StringTest::StringTest()
{

}

StringTest * elloop_test::StringTest::run()
{
    /*StupidDuplicateStringChecker checker("d:\\l.txt");
    string sameString = checker.returnFirstSameString();
    psln(sameString);*/
    string s("--window-size 480 800 --no-console       7");
    auto p = StringUtil::split(s, ' ');
    auto iter = p.begin();
    while (iter != p.end())
    {
        psln(*iter);
        ++iter;
    }
    return this;
}

elloop_test::StringTest::~StringTest()
{

}

void elloop_test::StringTest::testAssignment()
{
    string a("hello world");
    string b("hello kitty");

    string & c = a;
    c = b;
    b = a;
}

const std::string elloop_test::StupidDuplicateStringChecker::returnFirstSameString()
{
    if (fileName_ == "") {
        return "";
    }

    vector<string> allString;
    allString.reserve(500);

    ifstream inStream;
    string line("");
    inStream.open(fileName_.c_str(), ios::in);
    if (inStream.is_open()) {
        while (getline(inStream, line))
        {
            allString.push_back(line);
        }
    }

    inStream.close();

    pc("content of allString");
    psln(allString.size());
    //copy(allString.begin(), allString.end(), )
    for (auto s : allString) {
        psln(s);
    }

    pc("first same string:");
    for (int i = 0; i < allString.size(); ++i) {
        for (int j = i+1; j < allString.size(); ++j) {
            if (allString[i] == allString[j] && (i != j)) {
                return allString[i];
            }
        }
    }
        

    return "";
}
